<?php
ArrowController::importModel("org.arrowplatform.controls.presentation.table.columns.ArrowAbstractTableColumn");
ArrowController::importModel("smarty.SmartyCompiler");
class ArrowTableExtensibleColumn extends ArrowAbstractTableColumn{
	
	private $compiledLink;
	
	public function configure(){
		parent::configure();
		$this->addProperties(array("transport" => false));
		$this->setContentCodeKept(true);
		
	}
	
	public function init(){
		parent::init();
		
		$tmpArgs = array();
		$tmpArgs["model"] = "#model#";
		$tmpArgs["key"] = "#key#";
		
		$this->compiledLink = $this->getStateChangeLink(  $tmpArgs , true, false  );
		$this->registerJs( get_class($this), dirname(__FILE__)."/resources/".get_class($this).".js", ".".self::CTRL_NAMESPACE."-table-cell-expand"  );
		
	}
	
	public function generateRowCell( $context ){
		$args = array();
		$args["#model#"] = $context->getModel();
		$args["#key#"] = $context->getPKey();
		
		$href = strtr($this->compiledLink, $args);
	
		
		$text = ($this->getProperty("text"))?$this->getProperty("text"):$context[$this->getProperty("field")];
		$class = $this->getProperty("class") ;
		$str = '<td class="'.self::CTRL_NAMESPACE.'-table-cell-expand '.$class.'" >';
		$str.= $text;
		$str.=' <a href="'.$href.'" class="ctrl-action ctrl-action-expand">&nbsp;</a>';
		$str.=' <a href="" class="ctrl-action ctrl-action-piece">&nbsp;</a>';
		$str.='<div class="'.self::CTRL_NAMESPACE.'-table-cell-expand-area" >zzzzzzz</div>';
		$str.='</td>';
		return $str;
	}
	
	public function generateBlockStart(){
		$class = ArrowModel::getModelClass( $this->getState("model") );
		$context = call_user_func(array( $class, "getByKey" ),$this->getState("key"), $class );
		$compiler = new SmartyCompiler($this->getContentCode());
		$compiler->assign("context", $context);
		$compiler->assign("transport", $this->getProperty("transport"));
		return $compiler->getResult(array());
	}
	
	public function generateBlockEnd(){
		return "";
	}
	

}

?>